package com.aidex.system.controller;

import com.aidex.common.annotation.Log;
import com.aidex.common.core.controller.BaseController;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import com.aidex.system.domain.Waybill;
import com.aidex.system.service.WaybillService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 运单管理Controller
 * @author jmy
 * @email jmyinjg@163.com
 * @date 2021-10-04
 */
@RestController
@RequestMapping("/system/waybill")
public class WaybillController extends BaseController
{
    @Autowired
    private WaybillService waybillService;

    /**
     * 查询运单管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:waybill:list')")
    @GetMapping("/list")
    public R<PageInfo> list(Waybill waybill, HttpServletRequest request, HttpServletResponse response)
    {
        waybill.setPage(new PageDomain(request, response));
        return R.data(waybillService.findPage(waybill));
    }

    /**
     * 获取运单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:waybill:query')")
    @GetMapping(value = "/{id}")
    public R<Waybill> detail(@PathVariable("id") String id)
    {
        return R.data(waybillService.get(id));
    }

    /**
     * 新增运单管理
     */
    @PreAuthorize("@ss.hasPermi('system:waybill:add')")
    @Log(title = "运单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  Waybill waybill)
    {
        return R.status(waybillService.save(waybill));
    }

    /**
     * 修改运单管理
     */
    @PreAuthorize("@ss.hasPermi('system:waybill:edit')")
    @Log(title = "运单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated Waybill waybill)
    {
        return R.status(waybillService.save(waybill));
    }


    /**
     * 删除运单管理
     */
    @PreAuthorize("@ss.hasPermi('system:waybill:remove')")
    @Log(title = "运单管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(waybillService.deleteWaybillByIds(ids));
    }


    /**
     * 导出运单管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:waybill:export')")
    @Log(title = "运单管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(Waybill waybill)
    {
        List<Waybill> list = waybillService.findList(waybill);
        ExcelUtil<Waybill> util = new ExcelUtil<Waybill>(Waybill.class);
        return util.exportExcel(list, "waybill");
    }

}
